<?php

namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;

class Article extends Base
{
    use SoftDeletes;

    protected $fillable = ['id', 'user_id', 'title', 'file_path', 'type', 'is_join_album','longitude','latitude', 'city','weight'
        , 'activity_id','created_at', 'updated_at', 'latest_comment_at'];

    protected $casts = [
        'file_path' => 'array',
    ];

    const STATUS_NORMAL = 1;
    const STATUS_DELETE = 2;

    const TYPE_IMAGE = 1;
    const TYPE_VIDEO = 2;

    protected $hidden=['pivot'];

    public function setFilePathAttribute($val) {
        $this->attributes['file_path'] = $val;
    }

    public function circles() {
        return $this->belongsToMany(Circle::class, 'article_relate_circles', 'article_id', 'circle_id');
    }


    public function user() {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function is_star() {
        return $this->hasOne(Star::class, 'entity_id', 'id');
    }

    public function comment() {
        return $this->hasMany(Comment::class, 'entity_id');
    }

    public function article_tag() {
        return $this->belongsToMany(ArticleTag::class, 'article_tag_relates'
            , 'article_id', 'article_tag_id');
    }
}
